package www.bd.com;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author Berret
 * @date 2019/4/17 14:45
 * @discription :
 */
@Component
@RabbitListener(queues = "sms")
public class SmsListener {

    @Autowired
    private SmsUtil smsUtil;

    @Value("${aliyun.sms.template_code}")
    private String template_code;

    @Value("${aliyun.sms.sign_name}")
    private String sign_name;

    @RabbitHandler
    public void executeSms(Map<String,String> map){
        String checkCode = map.get("code");

        try {
            SendSmsResponse mobile = smsUtil.sendSms(map.get("mobile"), template_code, sign_name, "{\"code\":\""+checkCode+"\"}");
            System.out.println(mobile.getMessage());
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println("手机号"+map.get("mobile"));
        System.out.println("验证码"+map.get("code"));
    }
}
